from tortoise.models import Model
from tortoise import fields


# 安装 tortoise-orm   aiomysql  aerich tomlkit


class Student(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=120, description="姓名")
    pwd = fields.CharField(max_length=120, description="密码")
    sno = fields.IntField(unique=True, description="学号")

    # 班级id 学生对班级一对一  班级对学生一对多
    clas = fields.ForeignKeyField("models.Clas", related_name="students")

    # 课程和学生多对多
    course = fields.ManyToManyField("models.Course", related_name="students")


class Clas(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=120, description="班级名称")


# 课程
class Course(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=120, description="课程名称")
    # 一个老师有门课程
    teacher = fields.ForeignKeyField("models.Teacher", related_name="courses")
    addr = fields.CharField(max_length=32, description="教室")


class Teacher(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=120, description="老师名称")
    pwd = fields.CharField(max_length=120, description="密码")
    tno = fields.IntField(unique=True, description="编号")
